/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package htmlunit.code;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.SocketAddress;
import java.net.URL;
import java.net.URLConnection;
import javax.imageio.ImageIO;

/**
 *
 * @author TiTa
 */
public class luu_hinh {
     public static void main(String args[])
    {
        try {
              URL url = new URL("http://media6.tiin.vn/media01/4e66cf5ea8290/2013/04/01/9e8cce5f-06f1-4ef8-afe1-8364a9d900fe.jpg");
             // This is where you'd define the proxy's host name and port.
             SocketAddress address = new InetSocketAddress("http://media6.tiin.vn/media01/4e66cf5ea8290/2013/04/01/9e8cce5f-06f1-4ef8-afe1-8364a9d900fe.jpg", 80);
             
             // Create an HTTP Proxy using the above SocketAddress.
             Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
             
           
             
             // Open a connection to the URL using the proxy information.
             URLConnection conn = url.openConnection(proxy);
             InputStream inStream = conn.getInputStream();
             
             // BufferedImage image = ImageIO.read(url);
             // Use the InputStream flavor of ImageIO.read() instead.
             BufferedImage image = ImageIO.read(inStream);
             
             ImageIO.write(image, "JPG", new File("image.jpg"));
        } 
        catch (Exception e) {
             e.printStackTrace();
        }
    }
}
